<?php
/**
 * GameModel
 * 
 * @author Admin
 * @version 
 */
require_once 'Zend/Db/Table/Abstract.php';
class Admin_Models_NoteModel extends Zend_Db_Table_Abstract
{
    /**
     * The default table name 
     */
    protected $_name = 'tbl_groupnote';
    protected $_tblnote = 'tbl_note';
    protected $_primary = 'GroupNoteID';
    function loadlistgrouptoorder(){
        $db = Zend_Db_Table_Abstract::getDefaultAdapter();
        $mySql = $db->select()->from($this->_name)->where('main_event != 0')->order('ordering');
        $result = $db->fetchAll($mySql);
        return $result;
    }
    function search($search,$field,$group_id){
        $db = Zend_Db_Table_Abstract::getDefaultAdapter();
        $mySql = $db->select()->from($this->_name)->where($field ." LIKE '%".$search."%' AND GroupNoteID=".$group_id);
//        echo $mySql;
//        die;
        $result = $db->fetchAll($mySql);
        return $result;
    }
    function loadNoteGroup(){
        $db = Zend_Db_Table_Abstract::getDefaultAdapter();
        $mySql = $db->select()->from($this->_name)->where("main_event = 1");
        return $db->fetchAll($mySql);
    }
    
    function addNoteGroup($data){
    	$mySql = $this->insert($data); 
    	return $mySql;
    }
    function addNote($data){
       $db = Zend_Db_Table_Abstract::getDefaultAdapter();
       
    	$mySql = $db->insert('tbl_note', $data); 
    	return $mySql;
    }
    function listnote(){
        $db = Zend_Db_Table_Abstract::getDefaultAdapter();
        $mySql = $db->select()->from($this->_tblnote)->order('time_date DESC')  ;      
        $result = $db->fetchAll($mySql);
        return $result;
    }
    function listgroup(){
        $db = Zend_Db_Table_Abstract::getDefaultAdapter();
        $mySql = $db->select()->from('tbl_groupnote');
        $result = $db->fetchAll($mySql);
        return $result;
    }
    function loadgroupnamebyid($id){
         $db = Zend_Db_Table_Abstract::getDefaultAdapter();
        $mySql = $db->select()->from('tbl_groupnote')->where('GroupNoteID = '.$id);
        $result = $db->fetchAll($mySql);
        return $result;
    }
    function delgroupnote($id){
        $db = Zend_Db_Table_Abstract::getDefaultAdapter();
        try{
        
        $mySql = $db->delete('tbl_groupnote', 'count_note<=0 AND GroupNoteID ='.$id);
        }catch(Exception $e){
            echo $e;
        }
        return $mySql;
    }
    function delnote($id){
         $db = Zend_Db_Table_Abstract::getDefaultAdapter();
        try{
        $mySql = $db->delete('tbl_note', ' idnote ='.$id);
        }catch(Exception $e){
            echo $e;
        }
        return $mySql;
    }
    function updatenotegroup($data,$id){
        $db = Zend_Db_Table_Abstract::getDefaultAdapter();
        $mySql=$db->update($this->_name, $data, 'GroupNoteID='.$id);
        return $mySql;
    }
    
    function loadnotebyid($id){
         $db = Zend_Db_Table_Abstract::getDefaultAdapter();
        $mySql = $db->select()->from($this->_tblnote)->where('idnote = '.$id);
       //echo $mySql;die;
        $result = $db->fetchAll($mySql);
        return $result;
    }
    
    function updatenote($data,$id){
        $db = Zend_Db_Table_Abstract::getDefaultAdapter();
        $mySql=$db->update('tbl_note', $data, 'idnote='.$id);
        return $mySql;
    }

    
}